package com.swq.java.code.chapter13.code04;

public class Machine extends Thread {
    private int a = 0;  //实例变量

    public void run() {
        for (a = 0; a < 50; a++) {  //使用Machine对象的实例变量a
            System.out.println(currentThread().getName() + ":" + a);
            try {
                sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String args[]) throws InterruptedException {
        // 共享实例变量
        Machine machine = new Machine();
        machine.start();
        machine.run();

        // 不同的实例
        Machine machine1 = new Machine();
        machine1.start();
        Machine machine2 = new Machine();
        machine2.start();
    }
}